//Subject.java
package observer.newmodel;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *@author:youtubezou
 *@version:2012-7-30
 */
public abstract class Subject {
	private ArrayList<MyObserver> observers = new ArrayList<MyObserver>();
	
	public void attach(MyObserver observer){
		observers.add(observer);
	}
	
	public void detach(MyObserver observer){
		observers.remove(observer);
	}
	
	public void notifyObservers(){
		Iterator<MyObserver> iter = observers.iterator();
		
		while(iter.hasNext()){
			iter.next().update(getMessage());
		}
	}
	
	public abstract String getMessage();
}
